package com.cms.recursoshumanos.ui.directorio;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.decor.BorderFactory;

import com.cms.recursoshumanos.component.base.CustomListElement;
import com.cms.recursoshumanos.component.base.TwoColumnField;
import com.cms.recursoshumanos.component.base.URLBitmapField;
import com.cms.recursoshumanos.constant.Constant;
import com.cms.recursoshumanos.container.ForegroundManager;
import com.cms.recursoshumanos.container.ListStyleButtonSetManager;
import com.cms.recursoshumanos.container.TwoColumnFieldManager;
import com.cms.recursoshumanos.object.Contacto;
import com.cms.recursoshumanos.object.Persona;
import com.cms.recursoshumanos.ui.RecursosHumanosScreen;
import com.cms.recursoshumanos.utilities.Tool;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */

public final class DetailContactoScreen extends RecursosHumanosScreen
{
	public static DetailContactoScreen instance = null;
	
	private Contacto elContacto;
	
	private ForegroundManager _foreground;
	
	private URLBitmapField foto_persona;
	
	HorizontalFieldManager hfm;
	CustomListElement lblNombreContacto, lblApellidoContacto, 
						lblFechaNacContacto,lblSexoContacto,
						lblNroTlf1Contacto, lblNroTlf2Contacto, 
						lblDepartamentoContacto, lblEmail;
	TwoColumnFieldManager twoColumnManager;
	TwoColumnField twoColumnField,twoColumnField_EstrellaNombre;
	LabelField lblMensaje;
	Manager _content;
	
	
	public static DetailContactoScreen getInstance(Contacto elContacto)
	{
		if (instance == null)
		{
			instance = new DetailContactoScreen(elContacto);
		}
		return instance;
		
	}
	public DetailContactoScreen(Contacto elContacto) 
	{
		super(NO_VERTICAL_SCROLL | USE_ALL_HEIGHT);
		this.elContacto = elContacto;
		setComponents();
	}
	protected void makeMenu(Menu menu, int instance) 
	{
		MenuItem envio_email_contacto = new MenuItem("Enviar un Email", 0, 0) 
        {
			public void run() 
			{
				enviar_email(elContacto.getEmpleado().getPersona().getEmailPersona());
			}
		};
		MenuItem llamar_telefono_1 = new MenuItem("Llamar al Telefono "+
						elContacto.getEmpleado().getPersona().getTelefono_Persona_1(), 0, 0) 
        {
			public void run() 
			{
				llamar_numero(elContacto.getEmpleado().getPersona().getTelefono_Persona_1());
			}
		};
		MenuItem llamar_telefono_2 = new MenuItem("Llamar al Telefono "+
		elContacto.getEmpleado().getPersona().getTelefono_Persona_1(), 0, 0) 
        {
			public void run() 
			{
				llamar_numero(elContacto.getEmpleado().getPersona().getTelefono_Persona_2());
			}
		};
		menu.add(envio_email_contacto);
		menu.add(llamar_telefono_1);
		if (elContacto.getEmpleado().getPersona().getTelefono_Persona_2() != null)
		{
			menu.add(llamar_telefono_2);
		}
		super.makeMenu(menu, instance);
	}
	
	public void setComponents() 
	{
		setTitle("Detalle del Contacto");
		_foreground = new ForegroundManager();
		//_bodyWrapper = new NegativeMarginVerticalFieldManager(USE_ALL_WIDTH);
		
		
		
		twoColumnManager = new TwoColumnFieldManager( Display.getWidth() / 2, USE_ALL_WIDTH );
        twoColumnManager.setBorder( BorderFactory.createBitmapBorder( new XYEdges( 10, 10, 10, 10 ), Bitmap.getBitmapResource( "border_simple_white.png" ) ) );
        twoColumnManager.setMargin( 6, 6, 6, 6 );
        twoColumnManager.setPadding( 2, 2, 2, 2 );
        
        
        
        HorizontalFieldManager hfm_nombre_foto_estrella = new HorizontalFieldManager(USE_ALL_WIDTH);
     
        
        LabelField nombreContacto = new LabelField( elContacto.getEmpleado().getPersona().getApellido_Persona_1() +", "+
        		elContacto.getEmpleado().getPersona().getNombre_Persona_1() , 
        						FIELD_HCENTER |
								FIELD_VCENTER |
								DrawStyle.HCENTER |
								DrawStyle.VCENTER);
        nombreContacto.setFont(font_bold_8);
        
        
        foto_persona = new URLBitmapField();
        /*if (elContacto.getEmpleado().getPersona().getFoto_Persona() == null)
        {*/
        	foto_persona.setBitmap(Tool.getInstance().getContactoBlanco());
        /*}
        else
        {
        	foto_persona.setBitmap(elContacto.getEmpleado().getPersona().getFoto_Persona());
        }*/
        
        
        TwoColumnFieldManager twoColumnManager_foto_persona = new TwoColumnFieldManager( foto_persona.getWidth() , FIELD_HCENTER );
        twoColumnManager_foto_persona.setBorder( BorderFactory.createBitmapBorder( new XYEdges( 10, 10, 10, 10 ), Bitmap.getBitmapResource( "border_simple_white.png" ) ) );
        twoColumnManager_foto_persona.setMargin( 6, 0, 6, 0 );  
        twoColumnManager_foto_persona.add(foto_persona);
        
        
        
        BitmapField foto_star = null;
        
        if (elContacto.getFavorito())
        {
        	foto_star = new BitmapField(
            		Tool.getInstance().sizeImage(Bitmap.getBitmapResource("img/star_selec.png"), 
            				Tool.getInstance().getImgWidth(), 
            				Tool.getInstance().getImgHeight()).getBitmap(), FIELD_HCENTER);
        }
        else
        {
        	foto_star = new BitmapField(
            		Tool.getInstance().sizeImage(Bitmap.getBitmapResource("img/star_unselec.png"), 
            				Tool.getInstance().getImgWidth(), 
            				Tool.getInstance().getImgHeight()).getBitmap(), FIELD_HCENTER);
        }
        
        TwoColumnFieldManager twoColumnManager_estrella_icon = new TwoColumnFieldManager( foto_star.getWidth() , FIELD_HCENTER );
        twoColumnManager_estrella_icon.setBorder( BorderFactory.createBitmapBorder( new XYEdges( 10, 10, 10, 10 ), Bitmap.getBitmapResource( "border_simple_white.png" ) ) );
        twoColumnManager_estrella_icon.setMargin( 6, 0, 6, 0 );
        
        twoColumnManager_estrella_icon.add(foto_star);
       
        hfm_nombre_foto_estrella.add(twoColumnManager_foto_persona);
        hfm_nombre_foto_estrella.add(nombreContacto);
        //hfm_nombre_foto_estrella.add(twoColumnManager_estrella_icon);
        
        twoColumnManager.add(hfm_nombre_foto_estrella);
        
        
        //foto_comida.setMargin( 0, 10, 0, 10 );
        
        

        lblMensaje = new LabelField("Informacion Personal", LabelField.HCENTER | FIELD_HCENTER);
        lblMensaje.setFont(font_italic_7);
        
		twoColumnManager.add ( lblMensaje );
		Field separator = new SeparatorField();
        separator.setMargin( 2, 0, 2, 0 );
        twoColumnManager.add( separator );

        _content = new ListStyleButtonSetManager();
        
        setListComponents();
        
        _foreground.add(twoColumnManager);
        add(_foreground);
        
	}
	
	public Persona getPersona()
	{
		return this.elContacto.getEmpleado().getPersona();
	}
	public void setListComponents()
	{
		
		Font font = getFont().derive(Font.PLAIN, 6, Ui.UNITS_pt);
		int width = font.getAdvance("Telefono Secundario");
		
        lblNombreContacto = new CustomListElement("Nombre", elContacto.getEmpleado().getPersona().getNombre_Persona_1()+
        											" "+(elContacto.getEmpleado().getPersona().getNombre_Persona_2() == null ?
        														"" : elContacto.getEmpleado().getPersona().getNombre_Persona_2()), 
        											width) 
        {
			protected void paintBackground( Graphics g ) 
			{
				//// Modificacion para colores...
				///
				//
					COLOR_BACKGROUND_FOCUS = Constant.COLOR_FOCUS_NORMAL;
					COLOR_BACKGROUND_FOCUS_ACTION = Constant.COLOR_LIST_FOCUS;
				//
				///
				////
					
				
				  if( _drawPosition < 0 ) 
				  {
			          // it's like a list field, let the default background be drawn
			          super.paintBackground( g );
			          return;
			      }
			      
			      int oldColour = g.getColor();
			      int focus = COLOR_BACKGROUND_FOCUS;
			      if(_doAction)
			      {
			    	  focus = COLOR_BACKGROUND_FOCUS_ACTION;
			      }
			      
			      int background = g.isDrawingStyleSet( Graphics.DRAWSTYLE_FOCUS ) ? focus : Constant.COLOR_BACKGROUND;
			      
			      try 
			      {
			    	  
			          if( _drawPosition == 0 ) 
			          {
			              // Top
			              g.setColor( background );
			              g.fillRoundRect( 0, 0, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, 0, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.drawLine( 0, getHeight() - 1, getWidth(), getHeight() - 1 );
			          } 
			          else if( _drawPosition == 1 ) 
			          {
			              // Bottom 
			              g.setColor( background );
			              g.fillRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			          } 
			          else if( _drawPosition == 2 ) 
			          {
			              // Middle
			              g.setColor( background );
			              g.fillRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + 2 * CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + 2 * CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.drawLine( 0, getHeight() - 1, getWidth(), getHeight() - 1 );
			          } 
			          else 
			          {
			              // Single
			              g.setColor( background );
			              g.fillRoundRect( 0, 0, getWidth(), getHeight(), CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, 0, getWidth(), getHeight(), CORNER_RADIUS, CORNER_RADIUS );
			          }
			          g.drawLine(_preferedWidth+SEPARATOR_LONG, 0, _preferedWidth+SEPARATOR_LONG, getHeight());
			      } 
			      finally 
			      {
			          g.setColor( oldColour );
			      }
			  }
		}; 
		lblApellidoContacto = new CustomListElement("Apellido", 
													elContacto.getEmpleado().getPersona().getApellido_Persona_1()+
													" "+(elContacto.getEmpleado().getPersona().getApellido_Persona_2() == null ?
															"" : elContacto.getEmpleado().getPersona().getApellido_Persona_2()), 
													width) 
		{
			protected void paintBackground( Graphics g ) 
			{
				//// Modificacion para colores...
				///
				//
					COLOR_BACKGROUND_FOCUS = Constant.COLOR_FOCUS_NORMAL;
					COLOR_BACKGROUND_FOCUS_ACTION = Constant.COLOR_LIST_FOCUS;
				//
				///
				////
					
				
				  if( _drawPosition < 0 ) 
				  {
			          // it's like a list field, let the default background be drawn
			          super.paintBackground( g );
			          return;
			      }
			      
			      int oldColour = g.getColor();
			      int focus = COLOR_BACKGROUND_FOCUS;
			      if(_doAction) 
			    	  focus = COLOR_BACKGROUND_FOCUS_ACTION;
			      
			      int background = g.isDrawingStyleSet( Graphics.DRAWSTYLE_FOCUS ) ? focus : Constant.COLOR_BACKGROUND;
			      
			      try 
			      {
			    	  
			          if( _drawPosition == 0 ) 
			          {
			              // Top
			              g.setColor( background );
			              g.fillRoundRect( 0, 0, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, 0, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.drawLine( 0, getHeight() - 1, getWidth(), getHeight() - 1 );
			          } 
			          else if( _drawPosition == 1 ) 
			          {
			              // Bottom 
			              g.setColor( background );
			              g.fillRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			          } 
			          else if( _drawPosition == 2 ) 
			          {
			              // Middle
			              g.setColor( background );
			              g.fillRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + 2 * CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + 2 * CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.drawLine( 0, getHeight() - 1, getWidth(), getHeight() - 1 );
			          } 
			          else 
			          {
			              // Single
			              g.setColor( background );
			              g.fillRoundRect( 0, 0, getWidth(), getHeight(), CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, 0, getWidth(), getHeight(), CORNER_RADIUS, CORNER_RADIUS );
			          }
			          g.drawLine(_preferedWidth+SEPARATOR_LONG, 0, _preferedWidth+SEPARATOR_LONG, getHeight());
			      } 
			      finally 
			      {
			          g.setColor( oldColour );
			      }
			  }
		};
		lblFechaNacContacto = new CustomListElement("Fecha de Nacimiento", Tool.getInstance().parseDateToString(
				elContacto.getEmpleado().getPersona().getFecha_Nacimiento(),6), width) 
		{
			protected void paintBackground( Graphics g ) 
			{
				//// Modificacion para colores...
				///
				//
					COLOR_BACKGROUND_FOCUS = Constant.COLOR_FOCUS_NORMAL;
					COLOR_BACKGROUND_FOCUS_ACTION = Constant.COLOR_LIST_FOCUS;
				//
				///
				////
					
				
				  if( _drawPosition < 0 ) 
				  {
			          // it's like a list field, let the default background be drawn
			          super.paintBackground( g );
			          return;
			      }
			      
			      int oldColour = g.getColor();
			      int focus = COLOR_BACKGROUND_FOCUS;
			      if(_doAction) 
			    	  focus = COLOR_BACKGROUND_FOCUS_ACTION;
			      
			      int background = g.isDrawingStyleSet( Graphics.DRAWSTYLE_FOCUS ) ? focus : Constant.COLOR_BACKGROUND;
			      
			      try 
			      {
			    	  
			          if( _drawPosition == 0 ) 
			          {
			              // Top
			        	  
			              g.setColor( background );
			              g.fillRoundRect( 0, 0, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, 0, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.drawLine( 0, getHeight() - 1, getWidth(), getHeight() - 1 );
			          } 
			          else if( _drawPosition == 1 ) 
			          {
			              // Bottom 
			              g.setColor( background );
			              g.fillRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			          } 
			          else if( _drawPosition == 2 ) 
			          {
			              // Middle
			              g.setColor( background );
			              g.fillRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + 2 * CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + 2 * CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.drawLine( 0, getHeight() - 1, getWidth(), getHeight() - 1 );
			          } 
			          else 
			          {
			              // Single
			              g.setColor( background );
			              g.fillRoundRect( 0, 0, getWidth(), getHeight(), CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, 0, getWidth(), getHeight(), CORNER_RADIUS, CORNER_RADIUS );
			          }
			          g.drawLine(_preferedWidth+SEPARATOR_LONG, 0, _preferedWidth+SEPARATOR_LONG, getHeight());
			      } 
			      finally 
			      {
			          g.setColor( oldColour );
			      }
			  }
		};
		lblSexoContacto = new CustomListElement("Sexo", elContacto.getEmpleado().getPersona().getSexo_Persona(), width) 
		{
			protected void paintBackground( Graphics g ) 
			{
				//// Modificacion para colores...
				///
				//
					COLOR_BACKGROUND_FOCUS = Constant.COLOR_FOCUS_NORMAL;
					COLOR_BACKGROUND_FOCUS_ACTION = Constant.COLOR_LIST_FOCUS;
				//
				///
				////
					
				
				  if( _drawPosition < 0 ) 
				  {
			          // it's like a list field, let the default background be drawn
			          super.paintBackground( g );
			          return;
			      }
			      
			      int oldColour = g.getColor();
			      int focus = COLOR_BACKGROUND_FOCUS;
			      if(_doAction) 
			    	  focus = COLOR_BACKGROUND_FOCUS_ACTION;
			      
			      int background = g.isDrawingStyleSet( Graphics.DRAWSTYLE_FOCUS ) ? focus : Constant.COLOR_BACKGROUND;
			      
			      try 
			      {
			    	  
			          if( _drawPosition == 0 ) 
			          {
			              // Top
			              g.setColor( background );
			              g.fillRoundRect( 0, 0, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, 0, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.drawLine( 0, getHeight() - 1, getWidth(), getHeight() - 1 );
			          } 
			          else if( _drawPosition == 1 ) 
			          {
			              // Bottom 
			              g.setColor( background );
			              g.fillRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			          } 
			          else if( _drawPosition == 2 ) 
			          {
			              // Middle
			              g.setColor( background );
			              g.fillRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + 2 * CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + 2 * CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.drawLine( 0, getHeight() - 1, getWidth(), getHeight() - 1 );
			          } 
			          else 
			          {
			              // Single
			              g.setColor( background );
			              g.fillRoundRect( 0, 0, getWidth(), getHeight(), CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, 0, getWidth(), getHeight(), CORNER_RADIUS, CORNER_RADIUS );
			          }
			          g.drawLine(_preferedWidth+SEPARATOR_LONG, 0, _preferedWidth+SEPARATOR_LONG, getHeight());
			      } 
			      finally 
			      {
			          g.setColor( oldColour );
			      }
			  }
		};
		
		lblDepartamentoContacto = new CustomListElement("Departamento", 
				elContacto.getEmpleado().getDepartamento().getNombre_Departamento(), width) 
		{
			protected void paintBackground( Graphics g ) 
			{
				//// Modificacion para colores...
				///
				//
					COLOR_BACKGROUND_FOCUS = Constant.COLOR_FOCUS_NORMAL;
					COLOR_BACKGROUND_FOCUS_ACTION = Constant.COLOR_LIST_FOCUS;
				//
				///
				////
					
				
				  if( _drawPosition < 0 ) 
				  {
			          // it's like a list field, let the default background be drawn
			          super.paintBackground( g );
			          return;
			      }
			      
			      int oldColour = g.getColor();
			      int focus = COLOR_BACKGROUND_FOCUS;
			      if(_doAction) 
			    	  focus = COLOR_BACKGROUND_FOCUS_ACTION;
			      
			      int background = g.isDrawingStyleSet( Graphics.DRAWSTYLE_FOCUS ) ? focus : Constant.COLOR_BACKGROUND;
			      
			      try 
			      {
			    	  
			          if( _drawPosition == 0 ) 
			          {
			              // Top
			              g.setColor( background );
			              g.fillRoundRect( 0, 0, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, 0, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.drawLine( 0, getHeight() - 1, getWidth(), getHeight() - 1 );
			          } 
			          else if( _drawPosition == 1 ) 
			          {
			              // Bottom 
			              g.setColor( background );
			              g.fillRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			          } 
			          else if( _drawPosition == 2 ) 
			          {
			              // Middle
			              g.setColor( background );
			              g.fillRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + 2 * CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + 2 * CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.drawLine( 0, getHeight() - 1, getWidth(), getHeight() - 1 );
			          } 
			          else 
			          {
			              // Single
			              g.setColor( background );
			              g.fillRoundRect( 0, 0, getWidth(), getHeight(), CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, 0, getWidth(), getHeight(), CORNER_RADIUS, CORNER_RADIUS );
			          }
			          g.drawLine(_preferedWidth+SEPARATOR_LONG, 0, _preferedWidth+SEPARATOR_LONG, getHeight());
			      } 
			      finally 
			      {
			          g.setColor( oldColour );
			      }
			  }
		};
		
		lblEmail = new CustomListElement("Email", elContacto.getEmpleado().getPersona().getEmailPersona(), width) 
		{
			
			protected void paintBackground( Graphics g ) 
			{
				//// Modificacion para colores...
				///
				//
					COLOR_BACKGROUND_FOCUS = Constant.COLOR_FOCUS_NORMAL;
					COLOR_BACKGROUND_FOCUS_ACTION = Constant.COLOR_LIST_FOCUS;
				//
				///
				////
					
				
				  if( _drawPosition < 0 ) 
				  {
			          // it's like a list field, let the default background be drawn
			          super.paintBackground( g );
			          return;
			      }
			      
			      int oldColour = g.getColor();
			      int focus = COLOR_BACKGROUND_FOCUS;
			      if(_doAction) 
			    	  focus = COLOR_BACKGROUND_FOCUS_ACTION;
			      
			      int background = g.isDrawingStyleSet( Graphics.DRAWSTYLE_FOCUS ) ? focus : Constant.COLOR_BACKGROUND;
			      
			      try 
			      {
			    	  
			          if( _drawPosition == 0 ) 
			          {
			              // Top
			              g.setColor( background );
			              g.fillRoundRect( 0, 0, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, 0, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.drawLine( 0, getHeight() - 1, getWidth(), getHeight() - 1 );
			          } 
			          else if( _drawPosition == 1 ) 
			          {
			              // Bottom 
			              g.setColor( background );
			              g.fillRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			          } 
			          else if( _drawPosition == 2 ) 
			          {
			              // Middle
			              g.setColor( background );
			              g.fillRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + 2 * CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + 2 * CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.drawLine( 0, getHeight() - 1, getWidth(), getHeight() - 1 );
			          } 
			          else 
			          {
			              // Single
			              g.setColor( background );
			              g.fillRoundRect( 0, 0, getWidth(), getHeight(), CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, 0, getWidth(), getHeight(), CORNER_RADIUS, CORNER_RADIUS );
			          }
			          g.drawLine(_preferedWidth+SEPARATOR_LONG, 0, _preferedWidth+SEPARATOR_LONG, getHeight());
			      } 
			      finally 
			      {
			          g.setColor( oldColour );
			      }
			  }
		};
		
		lblNroTlf1Contacto = new CustomListElement("Telefono Primario", 
				elContacto.getEmpleado().getPersona().getTelefono_Persona_1(), width) 
		{
			protected boolean keyDown(int keycode,int time) 
			{
				// keycode == 1114112 para el send
				if(keycode == 1114112)
				{
					
					if( Dialog.ask(
							Dialog.D_YES_NO, 
							"Desea llamar al Telefono "+
							elContacto.getEmpleado().getPersona().getTelefono_Persona_1()+"?") == 4)
					{
						llamar_numero(elContacto.getEmpleado().getPersona().getTelefono_Persona_1());
					}
					
										
			        return true;
				}
				else
				{
					return super.keyDown(keycode, time);
				}
			}
			protected void paintBackground( Graphics g ) 
			{
				//// Modificacion para colores...
				///
				//
					COLOR_BACKGROUND_FOCUS = Constant.COLOR_FOCUS_NORMAL;
					COLOR_BACKGROUND_FOCUS_ACTION = Constant.COLOR_LIST_FOCUS;
				//
				///
				////
					
				
				  if( _drawPosition < 0 ) 
				  {
			          // it's like a list field, let the default background be drawn
			          super.paintBackground( g );
			          return;
			      }
			      
			      int oldColour = g.getColor();
			      int focus = COLOR_BACKGROUND_FOCUS;
			      if(_doAction) 
			    	  focus = COLOR_BACKGROUND_FOCUS_ACTION;
			      
			      int background = g.isDrawingStyleSet( Graphics.DRAWSTYLE_FOCUS ) ? focus : Constant.COLOR_BACKGROUND;
			      
			      try 
			      {
			    	  
			          if( _drawPosition == 0 ) 
			          {
			              // Top
			              g.setColor( background );
			              g.fillRoundRect( 0, 0, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, 0, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.drawLine( 0, getHeight() - 1, getWidth(), getHeight() - 1 );
			          } 
			          else if( _drawPosition == 1 ) 
			          {
			              // Bottom 
			              g.setColor( background );
			              g.fillRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			          } 
			          else if( _drawPosition == 2 ) 
			          {
			              // Middle
			              g.setColor( background );
			              g.fillRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + 2 * CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + 2 * CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.drawLine( 0, getHeight() - 1, getWidth(), getHeight() - 1 );
			          } 
			          else 
			          {
			              // Single
			              g.setColor( background );
			              g.fillRoundRect( 0, 0, getWidth(), getHeight(), CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, 0, getWidth(), getHeight(), CORNER_RADIUS, CORNER_RADIUS );
			          }
			          g.drawLine(_preferedWidth+SEPARATOR_LONG, 0, _preferedWidth+SEPARATOR_LONG, getHeight());
			      } 
			      finally 
			      {
			          g.setColor( oldColour );
			      }
			  }
		};
		lblNroTlf2Contacto = new CustomListElement("Telefono Secundario", 
				elContacto.getEmpleado().getPersona().getTelefono_Persona_2(), width) 
		{
			protected boolean keyDown(int keycode,int time) 
			{
				// keycode == 1114112 para el send
				if(keycode == 1114112)
				{
					
					if( Dialog.ask(
							Dialog.D_YES_NO, 
							"Desea llamar al Telefono "+
							elContacto.getEmpleado().getPersona().getTelefono_Persona_2()+"?") == 4)
					{
						llamar_numero(elContacto.getEmpleado().getPersona().getTelefono_Persona_2());
					}
					
										
			        return true;
				}
				else
				{
					return super.keyDown(keycode, time);
				}
			}
			protected void paintBackground( Graphics g ) 
			{
				//// Modificacion para colores...
				///
				//
					COLOR_BACKGROUND_FOCUS = Constant.COLOR_FOCUS_NORMAL;
					COLOR_BACKGROUND_FOCUS_ACTION = Constant.COLOR_LIST_FOCUS;
				//
				///
				////
					
				
				  if( _drawPosition < 0 ) 
				  {
			          // it's like a list field, let the default background be drawn
			          super.paintBackground( g );
			          return;
			      }
			      
			      int oldColour = g.getColor();
			      int focus = COLOR_BACKGROUND_FOCUS;
			      if(_doAction) 
			    	  focus = COLOR_BACKGROUND_FOCUS_ACTION;
			      
			      int background = g.isDrawingStyleSet( Graphics.DRAWSTYLE_FOCUS ) ? focus : Constant.COLOR_BACKGROUND;
			      
			      try 
			      {
			    	  
			          if( _drawPosition == 0 ) 
			          {
			              // Top
			              g.setColor( background );
			              g.fillRoundRect( 0, 0, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, 0, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.drawLine( 0, getHeight() - 1, getWidth(), getHeight() - 1 );
			          } 
			          else if( _drawPosition == 1 ) 
			          {
			              // Bottom 
			              g.setColor( background );
			              g.fillRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			          } 
			          else if( _drawPosition == 2 ) 
			          {
			              // Middle
			              g.setColor( background );
			              g.fillRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + 2 * CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, -CORNER_RADIUS, getWidth(), getHeight() + 2 * CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS );
			              g.drawLine( 0, getHeight() - 1, getWidth(), getHeight() - 1 );
			          } 
			          else 
			          {
			              // Single
			              g.setColor( background );
			              g.fillRoundRect( 0, 0, getWidth(), getHeight(), CORNER_RADIUS, CORNER_RADIUS );
			              g.setColor( COLOR_BORDER );
			              g.drawRoundRect( 0, 0, getWidth(), getHeight(), CORNER_RADIUS, CORNER_RADIUS );
			          }
			          g.drawLine(_preferedWidth+SEPARATOR_LONG, 0, _preferedWidth+SEPARATOR_LONG, getHeight());
			      } 
			      finally 
			      {
			          g.setColor( oldColour );
			      }
			  }
		};
		
        _content.add( lblNombreContacto );
        _content.add( lblApellidoContacto );
        _content.add( lblFechaNacContacto );
        _content.add( lblSexoContacto );
        _content.add( lblNroTlf1Contacto );
        if (elContacto.getEmpleado().getPersona().getTelefono_Persona_2() != null)
        {
            _content.add( lblNroTlf2Contacto );
        }
        _content.add( lblDepartamentoContacto );
        
        
        twoColumnManager.add(_content);
		
	}
	
	

}
